package oms.ck.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import oms.ck.service.sayService;

public class Servlet extends HttpServlet {
	
	private sayService service = new sayService(); 
	private String say = null;
	
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 设置编码格式
		request.setCharacterEncoding("utf-8");
		//获取浏览器端的请求路径
		String uri=request.getRequestURI();
		//将获取的请求资源路径uri进行字符串切割处理
		String path=uri.substring(uri.lastIndexOf("/"),uri.lastIndexOf("."));
		//根据处理后的字符串来判断用户的请求
		if(path.equals("/main")){
			//1、获取一个句子，将数据绑定到request对象上
			say = service.randomSentence();
			request.setAttribute("say", say);
			//2、获取转发器
			RequestDispatcher dis=request.getRequestDispatcher("main.jsp");
			//3、转发
			dis.forward(request, response);	
		}
	}

}
